﻿// using System.Linq;
// using Gp.Scripts.Core;
// using QFramework;
//
// namespace Gp.Scripts.Core {
//     public class TurnChain {
//         private TurnState[] _states = {TurnState.Attack, TurnState.Attack};
//         private FSM<TurnState> _turnState;
//         private int _curState = 0;
//         private TurnResolveAgent Agent => _turnState.CurrentState as TurnResolveAgent;
//         private TurnResolveController _controller;
//
//
//         public TurnChain(TurnResolveController controller) {
//             _turnState = new FSM<TurnState>();
//             _turnState.AddState(TurnState.Attack, new AttackTurnResolveAgent(_turnState, controller));
//             _turnState.AddState(TurnState.Defense, new DefenceTurnResolveAgent(_turnState, controller));
//
//             _turnState.StartState(CurState());
//         }
//
//
//         public bool NextState() {
//             _curState++;
//             if (CurState() != TurnState.RoundEnding) {
//                 _turnState.ChangeState(CurState());
//                 return false;
//             }
//
//             _curState = 0;
//             _turnState.ChangeState(CurState());
//             return true;
//         }
//
//
//         public TurnState CurState() {
//             return _curState >= _states.Length || _curState < 0 ? TurnState.RoundEnding : _states[_curState];
//         }
//
//         public TransitionResult ResolveTurn(BattleSettleRoot model) {
//             // 获取上一个行动玩家
//             var lastPlayer = model.CurrentPlayer.PlayerNumber;
//
//
//             // // 选择方向
//             // var other = lastPlayer == model.HumanPlayer.PlayerNumber
//             //     ? new TransitionResult(model.AIPlayer)
//             //     : new TransitionResult(placeHolder.playerLeft);
//             // var same = lastPlayer != placeHolder.playerLeft.PlayerNumber
//             //     ? new TransitionResult(placeHolder.playerRight)
//             //     : new TransitionResult(placeHolder.playerLeft);
//
//             // var res = Agent.SwitchSide() ? other : same;
//             var res = new TransitionResult(model.HumanPlayer) {
//                 PlayableUnits = () =>
//                     model.GetUnitsByPlayer(PlayerConst.PlayerUnitNumber).ToList()
//             };
//
//             return res;
//         }
//     }
//
//
//     public abstract class TurnResolveAgent : AbstractState<TurnState, TurnResolveController>, ICanSendEvent {
//         protected TurnResolveController Controller => mTarget;
//
//
//         public IArchitecture GetArchitecture() {
//             return MainArchitecture.Interface;
//         }
//
//         protected TurnResolveAgent(FSM<TurnState> fsm, TurnResolveController target) : base(fsm, target) { }
//
//         /// <summary>
//         /// 该轮结束后是否换边
//         /// </summary>
//         /// <returns></returns>
//         public abstract bool SwitchSide();
//     }
//
//
//     public class AttackTurnResolveAgent : TurnResolveAgent {
//         public AttackTurnResolveAgent(FSM<TurnState> fsm, TurnResolveController target) : base(fsm, target) { }
//
//         public override bool SwitchSide() {
//             return true;
//         }
//     }
//
//
//     public class DefenceTurnResolveAgent : TurnResolveAgent {
//         public DefenceTurnResolveAgent(FSM<TurnState> fsm, TurnResolveController target) : base(fsm, target) { }
//
//         public override bool SwitchSide() {
//             return false;
//         }
//     }
// }